package fivestar.ui.country;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

import org.jdesktop.swingx.JXBusyLabel;
import org.jdesktop.swingx.JXTable;
import org.pushingpixels.substance.api.skin.SubstanceBusinessBlackSteelLookAndFeel;
import javax.swing.ImageIcon;

public class Search extends javax.swing.JDialog implements ActionListener,
		ItemListener, MouseListener {

	private static final long serialVersionUID = 1051024041739122174L;
	private JPanel pnlGuest, pnlNorth, pnlCenter;
	public JCheckBox chkDNI;
	private JXTable tblCustomer;
	public DefaultTableModel dtmTabla;
	private JScrollPane scpTable;
	private TableColumn tc[];
	String[] cabecera = { "DNI", "Full Name" };
	String[][] data = {};
	int fila;
	private JPanel pnlSouth;
	private JPanel panel;
	JPanel pnlTitle;
	private JButton btnUpdate;
	private JButton btnNew;
	private JButton btnDelete;
	private JPanel panel_1;
	private JLabel lblNewLabel,lblNewLabel1;
	private JTextField textField;
	private JPanel panel_2;
	private JLabel primero;
	private JLabel anterior;
	private JLabel numeroDePagina;
	private JLabel siguiente;
	private JLabel ultimo;

	final int elementosPagina = 25;
	int paginaSeleccionada = 1;
	private int elementos = 0;
	int paginas = 1;

	// CargadorResultados cargador = null;
	// BuscadorResultados buscador = null;
	boolean primeraCarga = true;
	private JLabel resultadosEncontrados;
	private JXBusyLabel animacionCarga;
	private JButton btnNewButton_1;
	private JLabel lblCountry;
	JSeparator separator;
	JLabel lblGuest;

	public Search(Frame parent, boolean modal) {
		super(parent, modal);
		setTitle("Search Country");
		setResizable(false);
		initComponents();
		this.setLocationRelativeTo(null);
	}

	private void initComponents() {
		try {
			getContentPane().setLayout(new BorderLayout(0, 0));

			pnlGuest = new JPanel();
			getContentPane().add(pnlGuest);
			pnlGuest.setLayout(null);

			pnlTitle = new JPanel();
			pnlTitle.setBounds(10, 5, 452, 67);
			pnlGuest.add(pnlTitle);
			pnlTitle.setLayout(null);

			separator = new JSeparator();
			separator.setBounds(5, 36, 442, 2);
			pnlTitle.add(separator);

			lblGuest = new JLabel("Country");
			lblGuest.setHorizontalAlignment(SwingConstants.LEFT);
			lblGuest.setVerticalAlignment(SwingConstants.TOP);
			lblGuest.setFont(new Font("Tahoma", Font.PLAIN, 30));
			lblGuest.setBounds(10, 0, 233, 38);
			pnlTitle.add(lblGuest);

			lblNewLabel1 = new JLabel("Search");
			lblNewLabel1.setHorizontalAlignment(SwingConstants.LEFT);
			lblNewLabel1.setVerticalAlignment(SwingConstants.BOTTOM);
			lblNewLabel1.setForeground(new Color(0, 0, 0));
			lblNewLabel1.setFont(new Font("Tahoma", Font.PLAIN, 20));
			lblNewLabel1.setBounds(10, 36, 233, 27);
			pnlTitle.add(lblNewLabel1);
			
			pnlNorth = new JPanel();
			pnlNorth.setBorder(BorderFactory.createTitledBorder(null,
					"",
					TitledBorder.DEFAULT_JUSTIFICATION,
					TitledBorder.DEFAULT_POSITION, new Font("Comic Sans MS", 0,
							12)));
			pnlNorth.setBounds(10, 75, 450, 46);
			pnlGuest.add(pnlNorth);
			pnlNorth.setLayout(null);

			lblNewLabel = new JLabel("Country :");
			lblNewLabel.setBounds(10, 12, 89, 23);
			lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
			pnlNorth.add(lblNewLabel);

			textField = new JTextField();
			textField.setBounds(109, 12, 168, 23);
			textField.setHorizontalAlignment(SwingConstants.RIGHT);
			pnlNorth.add(textField);
			textField.setColumns(10);

			btnNewButton_1 = new JButton("");
			btnNewButton_1.setIcon(new ImageIcon(Search.class.getResource("/fivestar/ui/icons/refresh.png")));
			btnNewButton_1.setBounds(399, 12, 29, 23);
			pnlNorth.add(btnNewButton_1);

			pnlCenter = new JPanel();
			pnlCenter.setBorder(BorderFactory.createTitledBorder(null,
					"", TitledBorder.DEFAULT_JUSTIFICATION,
					TitledBorder.DEFAULT_POSITION, new Font("Comic Sans MS", 0,
							12)));
			pnlCenter.setBounds(10, 126, 450, 344);
			pnlGuest.add(pnlCenter);
			pnlCenter.setLayout(null);

			animacionCarga = new JXBusyLabel();
			animacionCarga.setFont(new Font("Tahoma", Font.BOLD, 11));
			animacionCarga.setBounds(150, 150, 120, 50);
			animacionCarga.setHorizontalAlignment(SwingConstants.CENTER);
			pnlCenter.add(animacionCarga);
			animacionCarga.setText("Loading...");
			animacionCarga.setBusy(true);

			// dtmTabla = new DefaultTableModel(data, cabecera);
			tblCustomer = new JXTable();
			tblCustomer.setFont(new Font("Comic Sans MS", Font.PLAIN, 11));
			tblCustomer.addMouseListener(this);
			scpTable = new JScrollPane(tblCustomer);
			scpTable.setBounds(6, 20, 438, 317);
			pnlCenter.add(scpTable);

			pnlSouth = new JPanel();
			pnlSouth.setBounds(10, 476, 450, 33);
			pnlGuest.add(pnlSouth);
			pnlSouth.setLayout(null);

			panel_2 = new JPanel();
			panel_2.setBounds(0, 0, 150, 33);
			pnlSouth.add(panel_2);

			lblCountry = new JLabel("Country ");
			panel_2.add(lblCountry);

			resultadosEncontrados = new JLabel("0");
			panel_2.add(resultadosEncontrados);

			panel_1 = new JPanel();
			panel_1.setBounds(150, 0, 150, 33);
			pnlSouth.add(panel_1);
			panel_1.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

			primero = new JLabel("");
			primero.setIcon(new ImageIcon(Search.class.getResource("/fivestar/ui/icons/first.gif")));
			primero.addMouseListener(this);
			panel_1.add(primero);

			anterior = new JLabel("");
			anterior.setIcon(new ImageIcon(Search.class.getResource("/fivestar/ui/icons/leftarrow.gif")));
			anterior.addMouseListener(this);
			panel_1.add(anterior);

			numeroDePagina = new JLabel("1");
			panel_1.add(numeroDePagina);

			siguiente = new JLabel("");
			siguiente.setIcon(new ImageIcon(Search.class.getResource("/fivestar/ui/icons/rightarrow.gif")));
			siguiente.addMouseListener(this);
			panel_1.add(siguiente);

			ultimo = new JLabel("");
			ultimo.setIcon(new ImageIcon(Search.class.getResource("/fivestar/ui/icons/last.gif")));
			ultimo.addMouseListener(this);
			panel_1.add(ultimo);

			panel = new JPanel();
			panel.setBounds(300, 0, 150, 33);
			pnlSouth.add(panel);

			btnNew = new JButton("...");
			btnNew.setBounds(10, 5, 25, 23);
			btnNew.addActionListener(this);
			panel.setLayout(null);
			panel.add(btnNew);

			btnUpdate = new JButton("...");
			btnUpdate.setBounds(80, 5, 25, 23);
			panel.add(btnUpdate);

			btnDelete = new JButton("...");
			btnDelete.setBounds(115, 5, 25, 23);
			panel.add(btnDelete);

			JButton btnNewButton = new JButton("...");
			btnNewButton.setBounds(45, 5, 25, 23);
			panel.add(btnNewButton);

			setSize(478, 545);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void itemStateChanged(ItemEvent e) {
		// TODO Auto-generated method stub

	}

	public static void main(String args[]) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					JDialog.setDefaultLookAndFeelDecorated(true);
					UIManager.setLookAndFeel(new SubstanceBusinessBlackSteelLookAndFeel());
				} catch (UnsupportedLookAndFeelException unsupportedLookAndFeelException) {
				}
				Search frame = new Search(null, true);
				frame.setVisible(true);

			}
		});
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == btnNew) {
			Register rg = new Register(null, true);
			rg.setVisible(true);
		}

	}
}
